package com.qjcc.controller;

import com.alibaba.fastjson.JSONObject;
import com.qjcc.config.MyWebSocket;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.Map;

/**
 * Created by HAHAHA on 2017/7/27.
 */
@RestController
public class HomeController {

    @ResponseStatus(HttpStatus.OK)
    @RequestMapping("/")
    public ModelAndView index() {
        return new ModelAndView("forward://index.html");
    }

    @RequestMapping("/workcard/from-call-center")
    public JSONObject workCard(@RequestBody Map<String, String> data) {
        System.out.println(data);
        try {
            MyWebSocket.sendInfo(JSONObject.toJSONString(data));
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success", "true");
        return jsonObject;
    }

}
